#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        <div id="datagridId"></div>

        <div id="datagridTb">
            <div class="row">
                <div class="col-md-12">
                    <form id="searchForm">
                        <div class="easyui-panel" title="信息查询" style="width:100%;padding:10px;"
                             data-options="iconCls:'icon-application_form'">

                            厂商： <input id="venIdSearch" class="easyui-combobox" style="width: 250px;" data-options=" valueField: 'ven_id',textField: 'vendor_alias',editable:false,url: '#(ctx)/equipment/findVendorList'">&nbsp;&nbsp;
                            设备型号: <input class="easyui-textbox" id="equModelSearch" style="width:200px">&nbsp;&nbsp;

                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true" onclick="datagridQuery();" iconCls="icon-zoom">#(_res.get('system.common.search'))</a>
                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true" onclick="$('#searchForm').form('clear');" iconCls="icon-zoom_out">#(_res.get('system.common.clear'))</a>
                        </div>
                    </form>
                </div>
                <div class="row">
                    <div class="col-md-12" style="padding: 5px 25px;">
                        #for(resource : resourceList)
                        <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'#(resource.icon)',plain:true" id='#(resource.url)'>#(_res.get(resource.resourceName))</a>
                        #end
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

#end


#define css()

#end


#define js()

<script type="text/javascript">
    var _datagrid = "datagridId", _form = "formId", _datagridTb = "datagridTb";
    var datagridListUrl = contextRootPath + '/equipment/list';

    $(function () {

        //初始化表格
        $("#" + _datagrid).datagrid({
            url: datagridListUrl,
            fit: true,
            border: false,
            rownumbers: true,
            pageSize: 30,
            toolbar: '#' + _datagridTb,
            singleSelect: false,
            pagination: true,
            nowrap: false,
            striped: true,
            fitColumns: true,
            columns: [[
                {
                    field: DBConts.TABLE_EQUIPMENT.EQU_ID,
                    title: DBConts.TABLE_EQUIPMENT.EQU_ID,
                    width: 100,
                    checkbox: true
                },
                {
                    field: DBConts.TABLE_VENDOR.VENDOR_ALIAS,
                    title: '厂商别名',
                    sortable: true
                },
                {
                    field: DBConts.TABLE_VENDOR.VENDOR_NAME,
                    title: '厂商名称',
                    sortable: true
                },
                {
                    field: DBConts.TABLE_EQUIPMENT.EQU_MODEL,
                    title: '设备型号',
                    sortable: true
                },
                {
                    field: DBConts.TABLE_EQUIPMENT_VERSION.EQU_VERSION,
                    title: '设备型号版本',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if(value === null || value === '') return 'ALL';
                        else return value;
                    }
                },
                {
                    field: 'createts',
                    title: "#(_res.get('user.form.creates'))",
                    sortable: true
                }
            ]]
        });


    #for(resource : resourceList)

        #if(resource.url == 'vendor_manager')
            $("##(resource.url)").on('click', function () {
                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 2000;
                params.height = 2000;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-shape_ungroup';
                params.url = contextRootPath + '/equipment/vendor';

                crud_dlg(params);
            });

        #elseif(resource.url == 'equipment_add')
            $("##(resource.url)").on('click', function () {
                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 700;
                params.height = 450;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-application_add';
                params.url = contextRootPath + '/equipment/add';
                params.buttons = [{
                    text: '提交',
                    iconCls: 'icon-application_go',
                    handler: function () {
                        datagrid_save('add');
                    }
                }, {
                    text: '重置',
                    iconCls: 'icon-application_side_contract',
                    handler: function () {
                        clearForm('formId')
                    }
                }];

                crud_dlg(params);
            });

        #elseif(resource.url == 'equipment_edit')
            $("##(resource.url)").on('click', function () {
                var selected = $('#' + _datagrid).datagrid('getSelected');


                if (selected == null) {
                    $.messager.alert("提示框", "请选择需要操作的设备!", "warning");
                    return;
                }

                var selections = $('#' + _datagrid).datagrid('getSelections');

                if (selections.length < 1) {
                    $.messager.alert("提示框", "请选择需要操作的设备!", "warning");
                    return;
                } else if (selections.length > 1) {
                    $.messager.alert("提示框", "编辑的设备为多个，请重新选择!", "warning");
                    return;
                }

                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 700;
                params.height = 400;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-application_edit';
                params.url = contextRootPath + '/equipment/edit/' + selected[DBConts.TABLE_EQUIPMENT.EQU_ID];
                params.buttons = [{
                    text: '提交',
                    iconCls: 'icon-application_go',
                    handler: function () {
                        datagrid_save();
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-application_side_contract',
                    handler: function () {
                        $('#crud_dlg').dialog('close');
                    }
                }];

                crud_dlg(params);
            });

        #elseif(resource.url == 'equipment_remove')
            $("##(resource.url)").on('click', function () {
                var selections = $('#' + _datagrid).datagrid('getSelections');
                var ids = "";
                var names = "";

                if (selections.length < 1) {
                    $.messager.alert("提示框", "请选择需要操作的设备!", "warning");
                    return;
                }

                $.messager.confirm('确认框', '请确定需要删除所选择的设备么？', function (r) {
                    if (r) {
                        $.each(selections, function (i, v) {
                            ids += v[DBConts.TABLE_EQUIPMENT.EQU_ID] + ",";
                            names += v[DBConts.TABLE_EQUIPMENT.EQU_MODEL] + ",";
                        });

                        $.post(contextRootPath + "/equipment/remove?ids=" + ids + "&equModels=" + names, function (data) {
                            var params = {};
                            params.element = _datagrid;
                            params.data = data;
                            params.isClose = false;
                            resultCallback(params);
                        }, 'json');
                    }
                });


            });

        #elseif(resource.url == 'vendor_allow')
            $("##(resource.url)").on('click', function () {
                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 2000;
                params.height = 2000;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-sitemap';
                params.url = contextRootPath + '/equipment/vendorAllow';


                crud_dlg(params);
            });

        #elseif(resource.url == 'equipment_forbid')

            $("##(resource.url)").on('click', function () {
                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 2000;
                params.height = 2000;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-sitemap_color';
                params.url = contextRootPath + '/equipment/equipmentForbid';


                crud_dlg(params);
            });

        #elseif(resource.url == 'device_forbid')

            $("##(resource.url)").on('click', function () {
                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 2000;
                params.height = 2000;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-sport_8ball';
                params.url = contextRootPath + '/equipment/deviceForbid';


                crud_dlg(params);
            });

        #elseif(resource.url == 'device_version')

        $("##(resource.url)").on('click', function () {
            var params = {};
            params.title = "#(_res.get(resource.resourceName))";
            params.width = 2000;
            params.height = 2000;
            params.top = '10px';
            params.modal = true;
            params.iconCls = 'icon-shape_ungroup';
            params.url = contextRootPath + '/equipment/deviceVersion';


            crud_dlg_device_version(params);
        });

        #end
    #end

    });


    function datagridQuery() {
        var venIdSearch = $("#venIdSearch");
        var equModelSearch = $("#equModelSearch");

        var flag = $("#searchForm").form('enableValidation').form('validate');

        if (!flag) return;

        $("#" + _datagrid).datagrid({
            queryParams: {
                "equipment.ven_id": venIdSearch.combobox("getValue"),
                "equipment.equ_model": equModelSearch.val()
            }
        });
    }



    function crud_dlg_device_version(params) {

        if (params.title == undefined) {
            params.title = "弹出框";
        }

        if (params.width == undefined) {
            params.width = $(window).width() - 50;
        } else {
            if ($(window).width() <= params.width) {
                params.width = $(window).width() - 50;
            }
        }

        if (params.height == undefined) {
            params.height = $(window).height() - 50;
        } else {
            if ($(window).height() <= params.height) {
                params.height = $(window).height() - 50;
            }
        }

        if (params.iconCls == undefined) {
            params.iconCls = 'fa fa-easyui fa-location-arrow fa-fw';
        }

        if (params.closed == undefined) {
            params.closed = false;
        }

        if (params.cache == undefined) {
            params.cache = false;
        }

        if (params.modal == undefined) {
            params.modal = false;
        }

        if (params.maximizable == undefined) {
            params.maximizable = false;
        }

        if (params.resizable == undefined) {
            params.resizable = true;
        }

        if (params.isParent == undefined) {
            params.isParent = false;
        }

        if (params.top == undefined) {
            params.top = "50px";
        }

        if (params.dlgId === undefined) {
            params.dlgId = 'crud_dlg';
        }

        if (params.buttons === undefined) {
            params.buttons = null;
        }

        var element = $('<div></div>');
        element.attr('id', params.dlgId);

        if (params.isParent) {
            element.appendTo(parent.document.body);
        } else {
            element.appendTo(document.body);
        }

        element.dialog({
            title: params.title,
            width: params.width,
            height: params.height,
            iconCls: params.iconCls,
            maximizable: params.maximizable,
            resizable: params.resizable,
            closed: params.closed,
            cache: params.cache,
            closeAnimation: 'fade',
            closeDuration: 600,
            loadingMessage: '数据正在加载中，请稍后...',
            href: params.url,
            modal: params.modal,
            buttons: params.buttons,
            top: params.top,
            onClose: function () {
                // 刷新弹窗的父页面
                window.location.reload(true);
                $(this).dialog("destroy");
            }
        });

        var position = "hcenter";//params.position || "center";//vcenter,hcenter,center

        element.dialog(position);
    }


</script>

#end



